import api from "../../http/apis/apis"

export default {
    namespaced: true,
    state: {
        userData: {
            gotUsers: [],
            total: 0,
            currentPage: 1,
            pageSize: 3,
            totalPages: 0
        }
    },
    mutations: {
        changePageSize(state, val) {
            state.userData.pageSize = val
        },
        // previousPage(state) {
        //     if (state.userData.currentPage > 1) {
        //         state.userData.currentPage--
        //     }
        // },
        // nextPage(state) {
        //     if (state.userData.currentPage < state.userData.totalPages) {
        //         state.userData.currentPage++
        //     }
        // },
        changeCurrentPage(state, val) {
            state.userData.currentPage = val
        }
    },
    actions: {
        async addUser(context, addUserData) {
            console.info("addUserdata", addUserData)
            let { data } = await api.userApi.addUser(addUserData)
            return data
        },
        async getAllUsers(context, searchType = "") {
            let userData = context.state.userData
            let sendData = { userData, searchType: searchType }
            let { data } = await api.userApi.getAllUsers(sendData)
            // console.log('user',data);
            const filteredData = data.data.gotUsers.filter(item => {
                return !item.deleted
            })
            context.state.userData = data.data
            context.state.userData.gotUsers = filteredData
        },

        async getUserByID(context, _id) {
            const { data } = await api.userApi.getUserByID({ _id })
            return data
        },
        async delUserByID(context, _id) {
            const { data } = await api.userApi.delUser({ _id })
            return data
        },
        async approveID(context,_id){
            const{data}=await api.userApi.approveID({_id})
            return data
        },
        async rejectID(context,_id){
            const{data}=await api.userApi.rejectID({_id})
            return data
        },
        async changeFrozenStatus(context,{_id,status}){
            const{data}=await api.userApi.changeFrozenStatus({_id,status})
            return data
        },
        async changeUserInfo(context,newUserData){
            const{data}=await api.userApi.changeUserInfo(newUserData)
            return data
        }
    },
    model: {
    }
}